package cn.diancan.action.manager;

import cn.diancan.action.BaseAction;
import cn.diancan.exception.OutMsgException;
import cn.diancan.manager.security.ManagerAuth;
import cn.diancan.model.MealLocation;
import cn.diancan.model.types.MealLocationStatusType;
import cn.diancan.model.types.MealLocationType;
import cn.diancan.vo.manager.MealLocationManagerActionVo;
import cn.diancan.vo.other.Pager;
import com.opensymphony.xwork2.ModelDriven;

/**
 *
 * @author Sky
 */
public class MealLocationAction extends BaseAction implements ModelDriven<MealLocationManagerActionVo>{

    private MealLocationManagerActionVo requestVo=new MealLocationManagerActionVo();

    private Pager pager = new Pager();

    //manager/MealLocation_mealLocationListPage
    @ManagerAuth
    public String mealLocationListPage(){
        try {
            pager.setPageNumber(requestVo.getPageNumber());
            pager.setPageSize(10);
            pager = mealLocationService.findMealLocationPager(pager);
            this.put("pager", pager);
            this.put("requestVo", requestVo);
            this.put("mealLocationTypeEnum", MealLocationType.values());
            this.put("mealLocationStatusTypeEnum", MealLocationStatusType.values());
            return freemarkView("/views/ftl/manager/meal_location/meal_location_list.ftl");
        } catch ( Exception e) {
            return managerError(e.getMessage());
        }
    }

    @ManagerAuth
    public String createMealLocationPage(){
        this.put("mealLocationTypeEnum", MealLocationType.values());
        this.put("mealLocationStatusTypeEnum", MealLocationStatusType.values());
        return freemarkView("/views/ftl/manager/meal_location/create_meal_location.ftl");
    }

    @ManagerAuth
    public String createMealLocation(){
        try {
            boolean b = mealLocationService.saveMealLocation(requestVo.vo2MealLocation());
            return jsonFormat(b,"添加成功","添加失败");
        } catch (OutMsgException e) {
            return jsonError(e);
        }catch (Exception e) {
            return jsonError("系统繁忙");
        }
    }

    @ManagerAuth
    public String mealLocationInfo(){
        try {
            MealLocation mealLocation = mealLocationService.findbyMealLocationId(requestVo.getMealLocationId());
            this.put("mealLocationTypeEnum", MealLocationType.values());
            this.put("mealLocationStatusTypeEnum", MealLocationStatusType.values());
            this.put("mealLocation",mealLocation);
            return freemarkView("/views/ftl/manager/meal_location/meal_location_info.ftl");
        } catch (OutMsgException e) {
            return managerError(e.getMessage());
        }catch (Exception e) {
            return managerError("系统繁忙");
        }
    }


    @ManagerAuth
    public String modifyMealLocation(){
        try {
            MealLocation mealLocation = requestVo.vo2MealLocation();
            mealLocation.setId(requestVo.getMealLocationId());
            boolean result = mealLocationService.updateMealLocation(mealLocation);
            return jsonFormat(result,"修改成功","修改失败");
        } catch (Exception e) {
            return jsonError(e);
        }
    }

  /*
    @ManagerAuth
    public String removeMealLocation(){
	try {
	    Boolean result = brandService.deleteBrandById(requestVo.getBrandId());
	    return jsonFormat(result,"删除成功","删除失败");
	} catch (OutMsgException e) {
	    return jsonError(e);
	}
    }*/



    @Override
    public MealLocationManagerActionVo getModel() {
        return requestVo;
    }
}
